package com.sskj.level.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.rxbus2.RxBus;
import com.sskj.common.util.ToastUtil;
import com.sskj.level.bean.TradeInfoBean;
import com.sskj.level.http.HttpConfig;
import com.sskj.level.ui.activity.TradeActivity;
import com.sskj.lib.RxBusCode;
import com.sskj.lib.box.LiveDataBus;
import com.sskj.lib.http.JsonCallBack;


public class TradeActivityPresenter extends BasePresenter<TradeActivity> {

    public void getRisk() {
        httpService.getTradeInfo()
                .execute(new JsonCallBack<HttpData<TradeInfoBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<TradeInfoBean>> response) {
                        HttpData<TradeInfoBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateTrade(httpData.getData());
                        }
                    }
                });
    }

    /**
     * 一键平仓
     */
    public void levelAllPc(String stockCode) {
        httpService.levelAllPc(stockCode)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData<TradeInfoBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            ToastUtil.showShort(httpData.getMsg());
                            LiveDataBus.get().with(RxBusCode.LEVEL_ALL_PC).postValue(1);
                        }
                    }
                });
    }
}
